import {User,UserListResponse} from '../types';
import apiClient from './client';

// 获取用户列表
export const getUserList = async (): Promise<UserListResponse> => {
  const response = await apiClient.get('/u/v1/user/list');
  return response.data;
};

// // 获取单个用户
// export const getUser = async (id: number): Promise<User> => {
//   const response = await apiClient.get(`/u/v1/user/${id}`);
//   return response.data;
// };

//修改密码
export const changePassword = async (id: number, passwordData: { new_password: string }): Promise<void> => {
  await apiClient.post(`/u/v1/user/changePassword/${id}`, passwordData);
};

// 添加用户
export const addUser = async (userData: { mobile: string; password: string }): Promise<User> => {
  const response = await apiClient.post('/u/v1/user/add', userData);
  return response.data;
};

// 更新用户
export const updateUser = async (id: number, userData: Partial<User>): Promise<User> => {
  const response = await apiClient.put(`/u/v1/user/update/${id}`, userData);
  return response.data;
};

// 删除用户
export const deleteUser = async (id: number): Promise<void> => {
  await apiClient.delete(`/u/v1/user/${id}`);
};

// 更新当前用户的个人信息
export const updateUserProfile = async (userData: Partial<User>): Promise<User> => {
  const response = await apiClient.put('/users/profile', userData);
  return response.data;
};

// 获取当前用户
export const getCurrentUser = async (): Promise<User> => {
  const response = await apiClient.get('/u/v1/user/current');
  return response.data;
};